home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Source Code / Visual Basic Source Code.iso / vbsource / dlaydr / dlaymain.frm (.txt) < prev    next >
Encoding:
Visual Basic Form  |  1995-05-08  |  5.7 KB  |  174 lines

  1. VERSION 2.00
  2. Begin Form MainForm 
  3.    BackColor       =   &H00E0E0E0&
  4.    BorderStyle     =   1  'Fixed Single
  5.    Caption         =   "Delayed Drag Demo"
  6.    ClientHeight    =   2490
  7.    ClientLeft      =   1845
  8.    ClientTop       =   2085
  9.    ClientWidth     =   3990
  10.    ControlBox      =   0   'False
  11.    Height          =   2895
  12.    Icon            =   DLAYMAIN.FRX:0000
  13.    Left            =   1785
  14.    LinkMode        =   1  'Source
  15.    LinkTopic       =   "Form1"
  16.    MaxButton       =   0   'False
  17.    ScaleHeight     =   2490
  18.    ScaleWidth      =   3990
  19.    Top             =   1740
  20.    Width           =   4110
  21.    Begin CommandButton Command1 
  22.       Caption         =   "Show Items in Cabinet"
  23.       Height          =   340
  24.       Left            =   120
  25.       TabIndex        =   5
  26.       Top             =   2080
  27.       Width           =   2415
  28.    End
  29.    Begin PictureBox FileCabinet 
  30.       AutoRedraw      =   -1  'True
  31.       BackColor       =   &H00E0E0E0&
  32.       BorderStyle     =   0  'None
  33.       Height          =   820
  34.       Left            =   3000
  35.       Picture         =   DLAYMAIN.FRX:0302
  36.       ScaleHeight     =   825
  37.       ScaleWidth      =   495
  38.       TabIndex        =   1
  39.       Top             =   1600
  40.       Width           =   495
  41.    End
  42.    Begin PictureBox FileCabinetClosed 
  43.       BackColor       =   &H00E0E0E0&
  44.       BorderStyle     =   0  'None
  45.       Height          =   820
  46.       Left            =   3360
  47.       Picture         =   DLAYMAIN.FRX:0604
  48.       ScaleHeight     =   825
  49.       ScaleWidth      =   495
  50.       TabIndex        =   2
  51.       Top             =   640
  52.       Visible         =   0   'False
  53.       Width           =   495
  54.    End
  55.    Begin PictureBox FileCabinetOpen 
  56.       BackColor       =   &H00E0E0E0&
  57.       BorderStyle     =   0  'None
  58.       Height          =   820
  59.       Left            =   2760
  60.       Picture         =   DLAYMAIN.FRX:0906
  61.       ScaleHeight     =   825
  62.       ScaleWidth      =   495
  63.       TabIndex        =   3
  64.       Top             =   640
  65.       Visible         =   0   'False
  66.       Width           =   495
  67.    End
  68.    Begin CommandButton Command2 
  69.       BackColor       =   &H00E0E0E0&
  70.       Caption         =   "Exit "
  71.       Height          =   380
  72.       Left            =   3000
  73.       TabIndex        =   0
  74.       Top             =   160
  75.       Width           =   735
  76.    End
  77.    Begin ListBox FileList 
  78.       DragIcon        =   DLAYMAIN.FRX:0C08
  79.       Height          =   1785
  80.       Left            =   120
  81.       Sorted          =   -1  'True
  82.       TabIndex        =   4
  83.       Tag             =   "SourceList"
  84.       Top             =   120
  85.       Width           =   2415
  86.    End
  87. ' The Delayed Drag Routine code is contained in the
  88. ' FileList_MouseMove event. The basic idea is to count
  89. ' how long the mouse is moved over a particular item (Marker)
  90. ' before dragging begins. It also checks to see whether the
  91. ' Marker is on a selected item and whether or not the cursor
  92. ' is in the listbox boundary before dragging begins.
  93. ' Since the users system clock will vary an "Adjuster" had to
  94. ' be determined to keep the delay the same for all users. I think
  95. ' it should do the trick. The API calls to determine "Showing"
  96. ' are necessary to determine the number of items that can be
  97. ' displayed in the listbox at one time. This can vary
  98. ' because of the users display. So these calls make sure we've
  99. ' got the right count.
  100. ' If you need any help, let me know and good luck!
  101. ' Jeff Simms  72200,3173
  102. DefInt A-Z
  103. Dim Marker As Integer
  104. Dim OldMarker As Integer
  105. Dim MouseTimer As Integer
  106. Dim Showing As Integer
  107. Dim Adjust As String
  108. Dim LRect As RECT
  109. Dim LBWRect As RECT
  110. Const LEFT_BUTTON = 1
  111. Const WM_USER = 1024
  112. Const LB_GETITEMRECT = WM_USER + 25
  113. Declare Function GetFocus Lib "User" () As Integer
  114. Declare Function SendMessage Lib "User" (ByVal hWnd As Integer, ByVal wMsg As Integer, ByVal wParam As Integer, lParam As Any) As Long
  115. Declare Sub GetWindowRect Lib "User" (ByVal hWnd As Integer, lpRect As RECT)
  116. Sub Command1_Click ()
  117.   CabinetList.Show
  118. End Sub
  119. Sub Command2_Click ()
  120.   End
  121. End Sub
  122. Sub FileCabinet_DragDrop (Source As Control, X As Single, Y As Single)
  123.      CabinetList.List1.AddItem Source.List(Source.ListIndex)
  124.      FileList.RemoveItem FileList.ListIndex
  125.      FileCabinet.Picture = FileCabinetClosed.Picture
  126. End Sub
  127. Sub FileCabinet_DragOver (Source As Control, X As Single, Y As Single, State As Integer)
  128.     Select Case State
  129.     Case 0
  130.     FileCabinet.Picture = FileCabinetOpen.Picture
  131.     Case 1
  132.     FileCabinet.Picture = FileCabinetClosed.Picture
  133.     End Select
  134. End Sub
  135. Sub FileList_GotFocus ()
  136.    Start! = Timer
  137.    For L = 1 To 25000: Next L
  138.    Finish! = Timer
  139.    Adjuster! = (Finish! - Start!) * 9
  140.    Adjust$ = Str$(Adjuster!)
  141.    FlhWnd = GetFocus()
  142.    GetWindowRect FlhWnd, LBWRect
  143.    I = SendMessage(FlhWnd, LB_GETITEMRECT, 0, LRect)
  144.    Y = LBWRect.bottom - LBWRect.top
  145.    X = LRect.bottom - LRect.top
  146.    Showing = Int(Y / X)
  147. End Sub
  148. Sub FileList_MouseMove (Button As Integer, Shift As Integer, X As Single, Y As Single)
  149.   If Button <> LEFT_BUTTON Or FileList.ListIndex = -1 Then MouseTimer = 0: Exit Sub
  150.       
  151.       OldMarker = Marker
  152.       Marker = Int((Y / FileList.Height) * Showing) + 1
  153.   If Marker > FileList.ListCount Then Exit Sub
  154.   If Marker = OldMarker Then
  155.        MouseTimer = MouseTimer + 1
  156.   Else
  157.        MouseTimer = 0
  158.   End If
  159.   If MouseTimer = Int(14 / Val(Adjust$)) + 1 And X > 0 And X < FileList.Width Then
  160.        FileList.Drag 1
  161.        MouseTimer = 0
  162.   End If
  163. End Sub
  164. Sub Form_Load ()
  165.     For X = 1 To 12
  166.     Number$ = Format$(X, "00")
  167.     FileList.AddItem "File Number " + Number$
  168.     Next X
  169.     FileList.ListIndex = 0
  170.     Show
  171.     FileList.SetFocus
  172. End Sub
  173.       
  174.